use crate::{SYS_PRINT, enter_syscall};

pub fn print(str: &str) {
    enter_syscall(str.as_ptr() as usize, str.len(), 0, 0, 0, 0, SYS_PRINT);
}

use core::fmt;
use core::fmt::Write;

struct Writer;

impl fmt::Write for Writer {
    fn write_str(&mut self, s: &str) -> fmt::Result {
        print(s);
        Ok(())
    }
}

#[inline]
pub fn _print(args: fmt::Arguments) {
    Writer.write_fmt(args).unwrap();
}

#[macro_export]
macro_rules! print {
    ($($arg:tt)*) => (
        $crate::debug::_print(format_args!($($arg)*))
    )
}

#[macro_export]
macro_rules! println {
    () => ($crate::print!("\n"));
    ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)))
}
